package com.felix.util;

import java.util.Map;

public class MakeSQL {
	
	public static String getCarShareSQL(Map<String,String[]> param,Map<Integer,Object> vars){
		int n = 0;
		StringBuffer sb =new StringBuffer("");
		if (param.get("fp")!=null&&!"".equals(param.get("fp")[0])) {
			sb.append("and from_city=? ");
			vars.put(n++,param.get("fp")[0]);
		}
		if (param.get("tp")!=null&&!"".equals(param.get("tp")[0])) {
			sb.append("and to_city=? ");
			vars.put(n++,param.get("tp")[0]);
		}
		if (param.get("sid")!=null) {
			if ("1".equals(param.get("sid")[0])) {
				sb.append("and car_sharer=1 ");
			}else if ("2".equals(param.get("sid")[0])) {
				sb.append("and car_sharer=0 ");
			}
		}
		if (param.get("trip")!=null) {
			if ("0".equals(param.get("trip")[0])) {
				sb.append("and trip_type=0 ");
			}else if ("1".equals(param.get("trip")[0])) {
				sb.append("and trip_type=1 ");
			}
		}
		if (param.get("uid")!=null&&!"".equals(param.get("uid")[0])) {
			sb.append("and uid = ?");
			vars.put(n++,param.get("uid")[0]);
			
		}
		if (param.get("tim")!=null&&!"".equals(param.get("tim")[0])) {
			sb.append("and gotime=? ");
			vars.put(n++,param.get("tim")[0]);
		}
		if (param.get("rtim")!=null&&!"".equals(param.get("rtim")[0])) {
			sb.append("and returntime=? ");
			vars.put(n++,param.get("rtim")[0]);
		}
		if (param.get("city")!=null&&!"".equals(param.get("city")[0])) {
			sb.append("and from_city in (");
			sb.append(param.get("city")[0]);
			sb.append(") ");
		}

		return sb.toString();
	}

}
